package com.syedu.day07.v1;

import cn.hutool.core.util.ArrayUtil;

/**
 * description：员工类
 *
 * 实体类(entity),包括属性,构造方法,get/set方法,...
 * 业务类(service),包括业务方法
 *
 * 封装策略:
 * 1.业务类和实体类合二为一,把业务方法写在实体类中,省去业务类的定义(小型系统)
 * 2.业务类和实体类分离,业务类只关注数据的定义(属性,构造,get/set),业务类关心业务功能,它们是分离的(中大型系统)
 */
public class Employee {
    private int id;//编号
    private String name;//姓名
    private double salary;//工资
    private Employee[] employees;//下属们,当前类的员工就是他们的上司

    public Employee() {
        
    }

    public Employee(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public Employee(int id, String name, double salary, Employee[] employees) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.employees = employees;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public Employee[] getEmployees() {
        return employees;
    }

    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }

    /**
     * 添加下属的方法
     */
    public void addEmp(Employee newEmployee){
        employees = ArrayUtil.append(employees,newEmployee);
    }

    /**
     * 输出自己所属下属的方法
     */
    public void showEmps() {
        if (employees != null && employees.length > 0) {
            for (Employee e : employees) {
                System.out.println(e.id + "," + e.name + "," + e.salary);
            }
        }
    }

    /**
     * 获取自己下属的人数个数
     */
    public int getEmpCount() {
        int count = 0;
        if (employees != null) {
            count = employees.length;
        }
        return count;
    }
}